<template>
  <div class="index-box">
    <el-container>
      <el-scrollbar style="background-color: #20222A;">
        <el-aside width="200px">
          <el-menu
            ref="menu"
            :default-openeds="openNames"
            :default-active="activeUrl"
            router
            background-color="#20222A"
            text-color="#fff"
            active-text-color="#fff"
          >
            <div class="layout-logo">LOGO</div>
            <template v-for="(item, index) in menuShowArr">
              <el-submenu :index="index + ''" v-if="item.children.length > 0">
                <template slot="title">
                  {{ item.title }}
                </template>
                <template v-for="(itemChild, indexChild) in item.children">
                  <el-menu-item
                    :index="itemChild.url"
                  >{{ itemChild.title }}</el-menu-item>
                </template>
              </el-submenu>
            </template>
          </el-menu>
        </el-aside>
      </el-scrollbar>
      <el-container>
        <el-header class="layout-header">
          <div class="layout-nav">
            <div class="layout-left">
              Smartint 后台管理系统
            </div>
            <div class="layout-right">
              <span class="layout-welcome">欢迎，Evelyn</span>
              <span class="layout-logout" @click="onClickLogout">
                <i class="el-icon-back"></i>退出登录
              </span>
            </div>
          </div>
        </el-header>
        <el-scrollbar style="height: calc(100vh - 60px);">
          <el-main>
            <router-view></router-view>
          </el-main>
        </el-scrollbar>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  data() {
    return {
      activeUrl: '',
      openNames: [],
      menuShowArr: [{
        title: '首页管理',
        children: [{
          id: '1-1',
          title: 'banner管理',
          url: '/banner-management'
        },{
          id: '1-2',
          title: '版面图片管理',
          url: '/picture-management'
        }]
      },{
        title: '活动管理',
        children: [{
          id: '2-1',
          title: '活动分类管理',
          url: '/activity-management'
        },{
          id: '2-2',
          title: '活动列表',
          url: '/activity-list'
        }]
      },{
        title: '问卷管理',
        children: [{
          id: '3-1',
          title: '问卷管理',
          url: '/questionnaire'
        }]
      },{
        title: '测评管理',
        children: [{
          id: '4-1',
          title: '测评列表',
          url: '/evaluation'
        }]
      },{
        title: '商城管理',
        children: [{
          id: '5-1',
          title: '商品分类管理',
          url: '/mall-classification'
        },{
          id: '5-2',
          title: '商品列表',
          url: '/mall-list'
        },{
          id: '5-3',
          title: '热门活动管理',
          url: '/mall-hot'
        }]
      },{
        title: '报表',
        children: [{
          id: '6-1',
          title: '订单报表',
          url: '/report-order'
        },{
          id: '6-2',
          title: '用户报表',
          url: '/report-user'
        },{
          id: '6-3',
          title: '申诉报表',
          url: '/report-complaint'
        },{
          id: '6-4',
          title: '开票报表',
          url: '/report-invoice'
        }]
      },{
        title: '后台管理',
        children: [{
          id: '7-1',
          title: '权限管理',
          url: '/background-permission'
        },{
          id: '7-2',
          title: '账号管理',
          url: '/report-account'
        }]
      }]
    }
  },
  mounted() {
    // activeUrl
    this.activeUrl = this.$route.path == '/index' ? '/banner-management' : this.$route.path
    this.$refs.menu.open(this.activeUrl)
  },
  methods: {
    onClickLogout() {
      sessionStorage.removeItem('token')
      this.$router.push('/')
    },
  }
}
</script>

<style>
p {
  margin: 0;
}
.el-scrollbar__wrap {
  overflow-x: hidden;
}
.el-header {
  background-color: #f8f8f9;
  color: #333;
}
.el-aside {
  background-color: #20222A;
  color: #333;
  overflow-x: hidden;
  padding-top: 60px;
}
.el-menu {
  border: 0;
}
.el-menu-item.is-active {
  background-color: #004e9e !important;
}
.el-main {
  background-color: #fff;
  color: #333;
}
.el-container {
  height: 100vh;
}
.layout-header {
  display: flex;
  align-items: center;
}
.layout-logo{
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 200px;
  height: 60px;
  line-height: 30px;
  background: #20222A;
  border-radius: 3px;
  color: #fff;
  z-index: 999;
}
.layout-nav{
  width: 100%;
  display: inline-flex;
  flex-direction: row;
  justify-content: space-between;
  color: #333;
}
.layout-nav .layout-left {
  font-size: 24px;
}
.layout-nav .layout-right {
  line-height: 30px;
}
.layout-nav .layout-right .layout-welcome {
  font-size: 18px;
  margin-right: 60px;
}
.layout-nav .layout-right .layout-logout {
  cursor: pointer;
  font-size: 16px;
}
.layout-nav .layout-right .layout-icon {
  font-size: 28px;
  position: relative;
  top: -1px;
  margin-right: 3px;
}
.table-header {
  background-color: #f8f8f9!important;
  font-size: 12px!important;
  padding: 5px!important;
}
.el-scrollbar__wrap {
  margin-bottom: 0!important;
}
.el-dialog__header {
  padding: 0!important;
}
</style>
